// 提供一份初始化的 state 数据
const initialState = {
  count: 0,
  todos: [
    {
      id: 1,
      title: "吃饭",
    },
  ],
};

// 提供一个 reducer 纯函数
function reducer(state = initialState, action: any) {
  // 基于 action.type 的不同，去返回一份全新的 state 数据
  switch (action.type) {
    case "increment":
      // state.count++
      // return state
      return {
        ...state,
        count: state.count + 1,
      };
    case "decremenet":
      return {
        ...state,
        count: state.count - 1,
      };
    case 'todos/add':
      return {
        ...state,
        todos: [...state.todos, action.payload]
      }
  
    default:
      return state;
  }
}

// 导出
export default reducer;
